import os
import cv2
import json

path = r'C:\Users\Admin\Desktop\imagedata\reline'
save_path = r'C:\Users\Admin\Desktop\imagedata\save_line'
for fname in os.listdir(path):
    with open(os.path.join(path,fname.strip()), 'r', encoding='utf-8') as f:
        data = json.load(f)
        shape = data["shapes"]
        print(fname.split(".")[0])
        print(len(shape) == 0)
        if len(data['shapes']) == 0:
            img_name = fname.split(".")[0]
            img_name = img_name + '.png'
            img = cv2.imread(os.path.join(r'C:\Users\Admin\Desktop\imagedata\retif',img_name))
            cv2.imwrite(os.path.join(r'C:\Users\Admin\Desktop\imagedata\456',img_name), img)
            continue
        json.dump(data, open(os.path.join(save_path, fname), 'w', encoding='utf-8'), indent=4)

